<script setup>
import { Menu as IconMenu, Setting } from '@element-plus/icons-vue'
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'

const activeIndex = ref('/profile/userInfo')
const route = useRoute()

function setCurrentRoute() {
  activeIndex.value = route.path
}
watch(
  () => activeIndex,
  (value, oldValue) => {
    setCurrentRoute()
    console.log(value, oldValue)
  },
  { immediate: true },
)
</script>

<template>
  <el-row class="h-full container">
    <el-col :span="12" class="h-full">
      <el-menu :default-active="activeIndex" class="h-full" :router="true">
        <el-menu-item index="/profile/userInfo">
          <template #title>
            <el-icon><IconMenu /></el-icon>
            <span>我的信息</span>
          </template>
        </el-menu-item>
        <el-menu-item index="/profile/myReserve">
          <el-icon><location /></el-icon>
          <span>预定记录</span>
        </el-menu-item>
        <el-menu-item index="/profile/myOrder">
          <el-icon><location /></el-icon>
          <span>我的订单</span>
        </el-menu-item>
        <el-menu-item index="/profile/myStar">
          <el-icon><location /></el-icon>
          <span>我的收藏</span>
        </el-menu-item>
        <el-menu-item index="/profile/settings">
          <el-icon><Setting /></el-icon>
          <span>设置</span>
        </el-menu-item>
      </el-menu>
    </el-col>
    <el-col :span="12">
      <div class="h-full w-full">
        <router-view />
      </div>
    </el-col>
  </el-row>
</template>

<style lang="scss" scoped>
.container {
  width: 40%;
}
</style>
